import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.util.*;
public class Driver{//runs 5 processes with bias towards completely fair scheduler
	static PrintStream contextfileOut;
	static PrintStream waitfileOut;
	static PrintStream turnaroundfileOut;
	public static void main(String[] args) throws FileNotFoundException{
		contextfileOut = new PrintStream(new File("context.csv"));
		waitfileOut = new PrintStream(new File("waitTime.csv"));
		turnaroundfileOut = new PrintStream(new File("turnaroundTime.csv"));
		ArrayList<Process> queue = new ArrayList<Process>();
		queue.add(new Process(1, 0, 10));
		queue.add(new Process(2, 1, 1));
		queue.add(new Process(3, 2, 2));
		queue.add(new Process(4, 3, 1));
		queue.add(new Process(5, 3, 5));
		System.out.println("==================");
		System.out.println("Shortest Job First");
		System.out.println("==================");
		simulate(new ShortestJobFirst(), queue, 5);
		System.out.println("===========");
		System.out.println("Round Robin");
		System.out.println("===========");
		simulate(new RoundRobin(), queue, 5);
		System.out.println("=======================");
		System.out.println("Completely Fair (Linux)");
		System.out.println("=======================");
		simulate(new CompletelyFair(), queue, 5);
		contextfileOut.close();
		waitfileOut.close();
		turnaroundfileOut.close();
	}
	public static void simulate(Scheduler s, ArrayList<Process> l, int processes){
		s.add_process(l);
		s.run();
		contextfileOut.println(processes + "," + s.context_switch_count);
		waitfileOut.println(processes + "," + s.waittotal);
		turnaroundfileOut.println(processes + "," + s.turntotal);
		for(int i = 0; i < l.size(); i++)
			l.get(i).reset();
	}
}
